import { SysNav } from '@/utils/interfaces';
import { Row, Col } from 'ant-design-vue';
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';

@Component({
  components: {
    'a-row': Row,
    'a-col': Col,
  }
})
export default class DeskMenu extends Vue {
  @Prop({
    type: Array,
    required: false,
    default: () => [],
  })
  sysNavs!: Array<any>;

  isGroup: number = 0;
  subSysNavs: Array<SysNav> = [];
  selectIndex: number = 0;

  private created() {
  }
  private activated() {
  }
  private mounted() {
    this.isGroup = +JSON.parse(sessionStorage.getItem('sysConfigMap') as string).SYSTEM_MENU_TYPE;
  }

  @Watch('sysNavs')
  getm(val: any) {
    this.subSysNavs = this.isGroup > 0 ? this.sysNavs[0].children : this.sysNavs;
  }


  /** 点击跳转到指定的系统 */
  specifySys(sysPath: string, sysId: any, sysName: string, iconImage: string, frameType: number) {
    if (sysId === undefined) {
      return;
    }
    let url = `/#${sysPath.indexOf('/') === 0 ? '' : '/'}${sysPath}`;
    if (frameType === 0) {
      url = `${window.location.origin}${url}`;
    } else if (frameType === 2) {
      url = `${window.location.origin}/${sysPath}&access_token=${sessionStorage.getItem('token')}`;
    }
    window.open(encodeURI(`${url}?sysName=${sysName}&iconImage=${iconImage}`), "_blank");
  }
}
